﻿
//我的信息
function loadStaff() {
    ajaxGet(siteApiList.GetInfo + "?id=" + staffId, function (data) {
        if (!isJsonSuccess(data))
            return;

        if (data.Data == null) return;
        var item = data.Data;
        var regionList = item.ProvinceName + "," + item.CityName + "," + item.AreaName;
        if (regionList) {
            setTimeout(function () {
                $("#selectdate").val(regionList);
            }, 100)
        }
        if (item.Regionid == 0) {
            $('#country1').addClass('choose_active');
        } else { $('#country2').addClass('choose_active'); }
        $('#selectdate').val(menu.substr(0, menu.length - 1));
        $("#hidAvater").val(item.Avater)
        $(".company").val(item.Company)
        $(".department").val(item.Department)
        $(".email").val(item.Email)
        $(".mobile").val(item.Mobile)
        $(".name").val(item.Name)
        $(".position").html(item.Position)
        $(".wxid").val(item.Wxid)
        $(".phone").val(item.Phone)
        $(".address").val(item.Address)
        $(".avater").attr("src", siteConfig.formatAvater(item.Avater))
        if (item.Regionid > 0)
            showAddress(0);
    });
}

var menu = '',regionids = '';
var isTrue = false;
function AreaIteration(data, regionId) {
    $.each(data, function (index, item) {
        if (item.id == regionId)
        {
            menu += item.name + ',';
            regionids = item.id;
            isTrue = true;
            return false;
        }
        if (isTrue) {
            menu += item.name + ',';
            return false;
        }
        if (item.child == undefined) return true;
        AreaIteration(item.child, regionId)
    })
}

//根据指定的ID，显示地区
function bindArea() {

}

//修改资料
function updateStaff() {
    var regions = area1.getValue();
    if(!regions){
        regions =  $("#selectdate").val(regionList);
    }
    regions = regions.split(",");
    var avater = $("#hidAvater").val()
    var name = $(".name").val()
    var wxid = $(".wxid").val()
    var phone = $(".phone").val()
    var mobile = $(".mobile").val()
    var company = $(".company").val()
    var email = $(".email").val()
    var address = $(".address").val()
    var regionid = 1;
    var ProvinceName = regions[0];
    var CityName = regions[1];
    var AreaName = regions[2] || "";
    var param = "id=" + staffId + "&avater=" + avater + "&name=" + name + "&wxid=" + wxid + "&phone=" + phone + "&mobile=" + mobile + "&company=" + company + "&email=" + email + "&address=" + address + "&regionid=" + regionid + "&ProvinceName=" + ProvinceName + "&CityName=" + CityName + "&AreaName=" + AreaName;
    ajaxPost(siteApiList.UpdateStaff, param, function (data) {
        if (!isJsonSuccess(data))
            return;

        Alert("保存成功");
    });
}

//切换地区
function showAddress(tabIndex) {
    $(".choose_country").removeClass("choose_active");
    $(".choose_country").eq(tabIndex).addClass("choose_active");

    $(".box-address").addClass("hide");
    if (tabIndex == 0) {
        $(".box-address").removeClass("hide");
        //validateAddress();
    }
}


function validateAddress() {
    var selectdate = $('#selectdate').val();
    var address = $('.address').val();

    if (selectdate == '') {
        Alert('请选择地区');
        return;
    }
    if (address == '') {
        Alert('请填写详细信息')
        return;
    }
}
